﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LiveSequence.Suite.Controls
{
  public class ExTreeView : TreeView
  {
    private ContextMenuStrip _treeViewMenuStrip;
    private ToolStripMenuItem _tsMnuCollapseAll;
    private ToolStripMenuItem _tsMnuExpandAll;
    private System.ComponentModel.IContainer components;


    public ExTreeView()
    {
      InitializeComponent();
      CanRaiseAfterCheckEvent = true;
      _tsMnuCollapseAll.Click += new EventHandler(_tsMnuCollapseAll_Click);
      _tsMnuExpandAll.Click += new EventHandler(_tsMnuExpandAll_Click);
      ContextMenuStrip = _treeViewMenuStrip;
    }

    void _tsMnuExpandAll_Click(object sender, EventArgs e)
    {
      if (this.SelectedNode != null)
      {
        this.SelectedNode.ExpandAll();
      }
      else
      {
        this.ExpandAll();
      }
    }

    void _tsMnuCollapseAll_Click(object sender, EventArgs e)
    {
      if (this.SelectedNode != null)
      {
        this.SelectedNode.Collapse();
      }
      else
      {
        this.CollapseAll();
      }
    }

    public bool CanRaiseAfterCheckEvent
    {
      get;
      set;
    }

    protected override void OnAfterCheck(TreeViewEventArgs e)
    {
      if (CanRaiseAfterCheckEvent)
      {
        base.OnAfterCheck(e);
      }
    }



    private void InitializeComponent()
    {
      this.components = new System.ComponentModel.Container();
      this._treeViewMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
      this._tsMnuCollapseAll = new System.Windows.Forms.ToolStripMenuItem();
      this._tsMnuExpandAll = new System.Windows.Forms.ToolStripMenuItem();
      this._treeViewMenuStrip.SuspendLayout();
      this.SuspendLayout();
      // 
      // _treeViewMenuStrip
      // 
      this._treeViewMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this._tsMnuCollapseAll,
            this._tsMnuExpandAll});
      this._treeViewMenuStrip.Name = "_treeViewMenuStrip";
      this._treeViewMenuStrip.Size = new System.Drawing.Size(137, 48);
      // 
      // _tsMnuCollapseAll
      // 
      this._tsMnuCollapseAll.Name = "_tsMnuCollapseAll";
      this._tsMnuCollapseAll.Size = new System.Drawing.Size(136, 22);
      this._tsMnuCollapseAll.Text = "Collapse All";
      // 
      // _tsMnuExpandAll
      // 
      this._tsMnuExpandAll.Name = "_tsMnuExpandAll";
      this._tsMnuExpandAll.Size = new System.Drawing.Size(136, 22);
      this._tsMnuExpandAll.Text = "Expand All";
      // 
      // ExTreeView
      // 
      this.LineColor = System.Drawing.Color.Black;
      this._treeViewMenuStrip.ResumeLayout(false);
      this.ResumeLayout(false);

    }


  }
}
